package com.finchina.myview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

/**
 * @author 黄赛赛
 * @version V1.0
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}()
 * @date 2015/10/2 18:39
 */
public class MyARCTileView extends View {

    int bgColor;

    int radius;
    int centerX, centerY;

    Paint mPaint;
    public MyARCTileView(Context context) {
        this(context, null);
    }

    public MyARCTileView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyARCTileView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        bgColor = Color.BLUE;
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DITHER_FLAG);
        mPaint.setColor(bgColor);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int w = getMeasuredWidth();
        int h = getMeasuredHeight();

        double b=  Math.pow(h / 3.0f, 2);
        double a = Math.pow(w / 2.0, 2);
//        double smallC = Math.sqrt(a+b);
        radius = (int) ((1.5*(a+b))/h);
        centerX = w/2;
        centerY = (int) (h / 3.0f *2- radius);
    }

    @Override
    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
        canvas.drawColor(Color.WHITE);

        canvas.drawCircle(centerX,centerY,radius,mPaint);
    }
}
